<template>
  <div>
    <!-- 上传榜单 2018/3/7 11:44 zhangQ -->
    <Row :style="{minHeight:350+'px'}">
      <i-col span="20" offset="4">
        <Form ref="uploadPoundForm" :model="uploadPoundForm" :rules="uploadPoundFormRules" label-position="left" :label-width="100">
          <Form-item label="毛重" prop="grossWeight">
            <Input v-model="uploadPoundForm.grossWeight" placeholder="请填写毛重" style="width: 200px"></Input>
          </Form-item>

          <Form-item label="毛重时间">
            <DatePicker v-model="uploadPoundForm.grossWeightTime" type="datetime" placeholder="请选择毛重时间"
                        style="width: 200px"></DatePicker>
          </Form-item>

          <Form-item label="皮重" prop="tareWeight">
            <Input v-model="uploadPoundForm.tareWeight" placeholder="请填写皮重" style="width: 200px"></Input>
          </Form-item>

          <Form-item label="皮重时间">
            <DatePicker v-model="uploadPoundForm.tareWeightTime" type="datetime" placeholder="请选择毛重时间"
                        style="width: 200px"></DatePicker>
          </Form-item>

          <Form-item label="净重" prop="netWeight">
            <Input v-model="uploadPoundForm.netWeight" placeholder="请填写净重" style="width: 200px"></Input>
          </Form-item>

          <Form-item label="磅单编号" prop="poundNo">
            <Input v-model="uploadPoundForm.poundNo" placeholder="请填写磅单编号" style="width: 200px"></Input>
          </Form-item>
        </Form>
      </i-col>
    </Row>
    <div class="xlinkModal-footer">
      <Button type="primary" @click="uploadPoundSubmit">确认上传榜单</Button>
    </div>
  </div>
</template>

<script>
  import moment from 'moment'
  import { uploadPound } from '@api/backEnd/fleetControl'

  export default {
    name: 'upload-pound',
    data () {
      let uploadPoundForm = {
        subOrderNo: '',
        containerNo: '',
        truckNo: '',
        grossWeight: 0,
        grossWeightTime: '',
        tareWeight: 0,
        tareWeightTime: '',
        netWeight: 0,
        poundNo: ''
      }
      let uploadPoundFormRules = {
        grossWeight: [
          { required: true, message: '毛重必填', trigger: 'blur' }
        ],
        grossWeightTime: [
          { required: true, message: '时间必填', trigger: 'blur' }
        ],
        tareWeight: [
          { required: true, message: '皮重必填', trigger: 'blur' }
        ],
        tareWeightTime: [
          { required: true, message: '时间必填', trigger: 'blur' }
        ],
        netWeight: [
          { required: true, message: '净重必填', trigger: 'blur' }
        ],
        poundNo: [
          { required: true, message: '磅单编号必填', trigger: 'blur' }
        ]
      }
      let datas = { uploadPoundForm, uploadPoundFormRules }
      return datas
    },
    props: {
      currentSubOrder: {
        type: Object,
        default () {
          return {}
        }
      }
    },
    computed: {},
    methods: {
      uploadPoundSubmit () {
        this.$refs['uploadPoundForm'].validate((valid) => {
          if (valid) {
            let subOrderNo = this.currentSubOrder.orderNO
            let containerNo = this.currentSubOrder.container_no
            let truckNo = this.currentSubOrder.truck_plate
            let grossWeight = this.uploadPoundForm.grossWeight
            let grossWeightTime = moment(this.uploadPoundForm.grossWeightTime).format('YYYY-MM-DD HH:mm:ss')
            let tareWeight = this.uploadPoundForm.tareWeight
            let tareWeightTime = moment(this.uploadPoundForm.tareWeightTime).format('YYYY-MM-DD HH:mm:ss')
            let netWeight = this.uploadPoundForm.netWeight
            let poundNo = this.uploadPoundForm.poundNo
            if (grossWeightTime && tareWeightTime && (grossWeightTime > tareWeightTime)) {
              this.$Message.error('时间有误！')
              return false
            }
            let param = {
              subOrderNo,
              containerNo,
              truckNo,
              grossWeight,
              grossWeightTime,
              tareWeight,
              tareWeightTime,
              netWeight,
              poundNo
            }
            uploadPound(param).then(res => {
              if (+res.data.isSuccess === 1) {
                this.$Message.success('磅单上传成功！')
                this.$emit('close', 'uploadPound')
              } else {
                this.$Message.error('发布失败请重试！')
                this.uploadPoundModel = true
              }
            })
          }
        })
      }
    },
    created () {
    },
    mounted () {
    },
    components: {}
  }
</script>

<style scoped>

</style>
